import os
from datetime import timedelta


class Config:
    """基础配置类"""
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-key'
    UPLOAD_FOLDER = 'app/static/uploads'
    METADATA_FOLDER = 'app/static/uploads/metadata'
    PUBLIC_IP = "8.218.194.27"
    DOMAIN = "voice-record.com"
    SSL_CERT = 'ssl/cert.pem'
    SSL_KEY = 'ssl/key.pem'

    # 缓存配置
    CACHE_TYPE = 'SimpleCache'
    CACHE_DEFAULT_TIMEOUT = 300

    # 会话配置
    PERMANENT_SESSION_LIFETIME = timedelta(days=7)

    # CSRF保护
    WTF_CSRF_ENABLED = True

    # 音频格式配置
    AUDIO_FORMAT = {
        'SAMPLE_RATE': 16000,
        'BIT_DEPTH': 16,
        'CHANNELS': 1
    }

    # 指令词列表
    COMMAND_WORDS = [
        # '小T小T',
        # 'play music',
        # 'stop music',
        # 'next song',
        # '上一首',
        # '下一首',
        # '开始播放',
        # '停止播放',
        # '暂停播放',
        # '恢复播放',
        # '继续播放',
        # '增大音量',
        # '减小音量'
        # 英语指令词
        "Previous Track",
        # "Next Track",
        # "Increase Volume",
        # "Decrease Volume",
        # "Start playing",
        # "Resume playing",
        # "Pause Audio",
        # "ANC Mode",
        # "Turn On ANC",
        # "Activate ANC",
        # "Transparent Mode",
        # "Adaptive Mode",
        # "Answer Call",
        # "Reject Call",
        # "Start Translation",
        # "Start Recording",
        # "End Recording",
        # "Hey Siri",

        # 日语指令词
        # "前の曲",
        # "戻って",
        # "次の曲",
        # "進んで",
        # "音量アップ",
        # "音量を上げて",
        # "音量ダウン",
        # "音量を下げて",
        # "音楽かけて",
        # "再生",
        # "一時停止",
        # "ノイズキャンセリングモード",
        # "ノイズキャンセリング",
        # "ノイズキャンセリングをオン",
        # "外取り込み",
        # "自動でノイキャンを調整",
        # "応答",
        # "電話に出て",
        # "着信拒否",
        # "電話を切る",
        # "翻訳開始",
        # "録音開始",
        # "録音終了",

        # 德语(German)
        # "Vorheriger Titel",
        # "Vorheriges Lied",
        # "Nächster Titel",
        # "Nächstes Lied",
        # "Lautstärke hoch",
        # "Lautstärke runter",
        # "Jetzt spielen",
        # "Jetzt abspielen",
        # "Weiter spielen",
        # "Weiter abspielen",
        # "Wiedergabe anhalten",
        # "Geräuschunterdrückung an",
        # "Noise Cancelling an",
        # "Geräuschunterdrückung aktivieren",
        # "Transparenzmodus",
        # "Adaptiver Modus",
        # "Adaptiver Modus an",
        # "Anruf annehmen",
        # "Ablehnen",
        # "Übersetzung starten",
        # "Aufnahme starten",
        # "Aufnahme beenden",
    ]

    # 速度设置
    SPEEDS = ['正常', '慢', '快']

    # 重复次数设置
    REPETITIONS = 2  # 每个单词需要重复的次数


class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True
    PORT = 5000
    HOST = '0.0.0.0'
    SSL_CONTEXT = None  # 开发环境不使用SSL

    # 开发环境缓存配置
    CACHE_TYPE = 'SimpleCache'


class TestingConfig(Config):
    """测试环境配置"""
    TESTING = True
    DEBUG = True
    PORT = 5000
    HOST = '0.0.0.0'
    SSL_CONTEXT = None

    # 测试环境禁用CSRF保护
    WTF_CSRF_ENABLED = False

    # 测试环境使用空缓存
    CACHE_TYPE = 'NullCache'


class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False
    TESTING = False
    CACHE_TYPE = 'simple'
    HOST = '0.0.0.0'
    PORT = 443  # 修改为HTTPS标准端口
    SSL_CONTEXT = ('ssl/cert.pem', 'ssl/key.pem')  # 启用SSL


# 根据环境变量选择配置
config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}


def get_config():
    """获取当前环境的配置"""
    env = os.environ.get('FLASK_ENV', 'default')
    return config.get(env, config['default'])
